/*
 * Tint Browser for Android
 * 
 * Copyright (C) 2012 - to infinity and beyond J. Devauchelle and contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package com.cnbrowser.android.ui.cbrowser;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cnbrowser.android.R;

public class WebsiteAdapter extends ArrayAdapter {

    private final Website[] websites;


    private final LayoutInflater inflater;

    public WebsiteAdapter(Context context, int resource, Website[] websites) {
        super(context, resource, websites);
        this.websites=websites;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        RelativeLayout layout = new RelativeLayout(getContext());
        inflater.inflate(R.layout.cb_start_page_left_fragment_item, layout, true);

        ImageView imageView = (ImageView) layout.findViewById(R.id.websiteIcon);
        TextView name = (TextView) layout.findViewById(R.id.websiteName);

        name.setText(websites[position].getName());
        imageView.setImageResource(websites[position].getIcon());

        layout.setTag(websites[position].getUrl());

        return layout;
    }
}
